package com.zircloud.tenant.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zircloud.tenant.dto.UserInfoDto;
import com.zircloud.tenant.entity.UserInfo;
import com.zircloud.tenant.mapper.UserInfoMapper;
import com.zircloud.tenant.service.UserInfoService;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author test
 * @since 2022-01-06
 */
@Service
public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements UserInfoService {
	
	
	@Autowired
	private UserInfoMapper mapper;

	@Override
	public UserInfoDto getUserByid(Integer id) {
		UserInfo user = mapper.selectById(id);
		if(user!=null) {
			UserInfoDto dto = new UserInfoDto();
			BeanUtils.copyProperties(user, dto);
			return dto;
		}
		return null;
	}

	@Override
	public UserInfoDto getUserByname(String name) {
		QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<UserInfo>();
		queryWrapper.eq("name",name);
		
		UserInfo user = mapper.selectOne(queryWrapper);
		if(user!=null) {
			UserInfoDto dto = new UserInfoDto();
			BeanUtils.copyProperties(user, dto);
			return dto;
		}
		return null;
	}

	@Override
	public boolean creaate(UserInfoDto dto) {
		if(dto!=null) {
			UserInfo user = new UserInfo();
			BeanUtils.copyProperties(dto, user);
			return mapper.insert(user)>0;
		}
		return false;
	}

}
